I’m trying to create a small game as a learning experience and I’m having trouble adding a jump function. The game is for mobile touch screens.
Essentially I have a gravity variable which is applied to the player on the canvas (which works fine) and an accelerate function for up/down movement.
I need to be able to tap the screen and have the "player" jump, then fall back down. so far I have:
document.addEventListener
(“touchstart”,jump)
function jump() {
accelerate(-0.5);
}
document.addEventListner
("touchend”,fall)
function fall() {
accelerate(0.4)
}
I might not have remembered what I wrote exactly, but the above code works for rising and falling, the problem however is if the user holds the screen, the player will just keep rising. Now obviously logically this is to be expected but I want more of a tap screen to jump type thing
so is there a way to have the accelerate run once when the user taps the screen, perhaps for a set duration then stops, until the screen is tapped again?
sorry for the long post